FROM golang:alpine as builder

WORKDIR /server

COPY  . .

RUN go env -w GO111MODULE=on
RUN go env -w GOPROXY=https://goproxy.cn,direct
RUN go env -w CGO_ENABLED=0
RUN go mod tidy
RUN go build -o server .

FROM alpine:latest
LABEL MAINTAINER debugksir<402351681@qq.com>

WORKDIR /server

COPY --from=builder /server ./

EXPOSE 8080

ENV GIN_MODE=$GIN_MODE

RUN ["chmod","+x","./wait-for-it-sh.sh"]

# ENTRYPOINT ./server
# 虽然加上了depends-on:mysql,但仅仅保证mysql处于running状态，我们需要在ready状态之后启动server，所以在这里加上了wait-for-it-sh.sh做处理
ENTRYPOINT ["./wait-for-it-sh.sh", "172.1.0.12:3306", "--", "./server"]